<script setup>
import { ProductService } from '@/service/ProductService';
import { onMounted, ref } from 'vue';

const products = ref(null);
const layout = ref('grid');

const items = ref([
    { label: 'Add New', icon: 'pi pi-fw pi-plus' },
    { label: 'Remove', icon: 'pi pi-fw pi-trash' }
]);

onMounted(() => {
    ProductService.getProductsSmall().then((data) => (products.value = data));
});
const getSeverity = (status) => {
    switch (status) {
        case 'INSTOCK':
            return 'success';

        case 'LOWSTOCK':
            return 'warning';

        case 'OUTOFSTOCK':
            return 'danger';

        default:
            return null;
    }
};
</script>

<template>
    <div class="card">
        <div class="font-semibold text-xl mb-4">My Material</div>
        <Tabs value="0">
            <TabList>
                <Tab value="0">Image</Tab>
                <Tab value="1">Video</Tab>
                <Tab value="2">Canva</Tab>
            </TabList>
            <TabPanels>
                <TabPanel value="0">
                    <DataView :value="products" :layout="layout">
                        <template #grid="slotProps">
                            <div class="grid grid-cols-12 gap-4">
                                <div v-for="(item, index) in slotProps.items" :key="index" class="col-span-12 sm:col-span-6 lg:col-span-3 p-2">
                                    <div class="p-6 border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-900 rounded flex flex-col">
                                        <div class="bg-surface-50 flex justify-center rounded p-4">
                                            <div class="relative mx-auto">
                                                <img class="rounded w-full" :src="`https://primefaces.org/cdn/primevue/images/product/${item.image}`" :alt="item.name" style="max-width: 300px" />
                                                <Tag :value="item.inventoryStatus" :severity="getSeverity(item)" class="absolute dark:!bg-surface-900" style="right: 5px; bottom: 5px"></Tag>
                                            </div>
                                        </div>
                                        <div class="pt-6">
                                            <div class="flex flex-row justify-between items-start gap-2">
                                                <div>
                                                    <span class="font-medium text-surface-500 dark:text-surface-400 text-sm">{{ item.category }}</span>
                                                    <div class="text-lg font-medium mt-1">{{ item.name }}</div>
                                                </div>
                                                <div class="bg-surface-100 p-1" style="border-radius: 30px">
                                                    <div
                                                        class="bg-surface-0 flex items-center gap-2 justify-center py-1 px-2"
                                                        style="
                                                            border-radius: 30px;
                                                            box-shadow:
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.04),
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.06);
                                                        "
                                                    >
                                                        <span class="text-surface-900 font-medium text-sm">{{ item.rating }}</span>
                                                        <i class="pi pi-star-fill text-yellow-500"></i>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="flex flex-col gap-6 mt-6">
                                                <span class="text-2xl font-semibold">${{ item.price }}</span>
                                                <div class="flex gap-2">
                                                    <Button icon="pi pi-shopping-cart" label="Buy Now" :disabled="item.inventoryStatus === 'OUTOFSTOCK'" class="flex-auto whitespace-nowrap"></Button>
                                                    <Button icon="pi pi-heart" outlined></Button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </DataView>
                </TabPanel>
                <TabPanel value="1">
                    <DataView :value="products" :layout="layout">
                        <template #grid="slotProps">
                            <div class="grid grid-cols-12 gap-4">
                                <div v-for="(item, index) in slotProps.items" :key="index" class="col-span-12 sm:col-span-6 lg:col-span-3 p-2">
                                    <div class="p-6 border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-900 rounded flex flex-col">
                                        <div class="bg-surface-50 flex justify-center rounded p-4">
                                            <div class="relative mx-auto">
                                                <img class="rounded w-full" :src="`https://primefaces.org/cdn/primevue/images/product/${item.image}`" :alt="item.name" style="max-width: 300px" />
                                                <Tag :value="item.inventoryStatus" :severity="getSeverity(item)" class="absolute dark:!bg-surface-900" style="right: 5px; bottom: 5px"></Tag>
                                            </div>
                                        </div>
                                        <div class="pt-6">
                                            <div class="flex flex-row justify-between items-start gap-2">
                                                <div>
                                                    <span class="font-medium text-surface-500 dark:text-surface-400 text-sm">{{ item.category }}</span>
                                                    <div class="text-lg font-medium mt-1">{{ item.name }}</div>
                                                </div>
                                                <div class="bg-surface-100 p-1" style="border-radius: 30px">
                                                    <div
                                                        class="bg-surface-0 flex items-center gap-2 justify-center py-1 px-2"
                                                        style="
                                                            border-radius: 30px;
                                                            box-shadow:
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.04),
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.06);
                                                        "
                                                    >
                                                        <span class="text-surface-900 font-medium text-sm">{{ item.rating }}</span>
                                                        <i class="pi pi-star-fill text-yellow-500"></i>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="flex flex-col gap-6 mt-6">
                                                <span class="text-2xl font-semibold">${{ item.price }}</span>
                                                <div class="flex gap-2">
                                                    <Button icon="pi pi-shopping-cart" label="Buy Now" :disabled="item.inventoryStatus === 'OUTOFSTOCK'" class="flex-auto whitespace-nowrap"></Button>
                                                    <Button icon="pi pi-heart" outlined></Button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </DataView>
                </TabPanel>
                <TabPanel value="2">
                    <DataView :value="products" :layout="layout">
                        <template #grid="slotProps">
                            <div class="grid grid-cols-12 gap-4">
                                <div v-for="(item, index) in slotProps.items" :key="index" class="col-span-12 sm:col-span-6 lg:col-span-3 p-2">
                                    <div class="p-6 border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-900 rounded flex flex-col">
                                        <div class="bg-surface-50 flex justify-center rounded p-4">
                                            <div class="relative mx-auto">
                                                <img class="rounded w-full" :src="`https://primefaces.org/cdn/primevue/images/product/${item.image}`" :alt="item.name" style="max-width: 300px" />
                                                <Tag :value="item.inventoryStatus" :severity="getSeverity(item)" class="absolute dark:!bg-surface-900" style="right: 5px; bottom: 5px"></Tag>
                                            </div>
                                        </div>
                                        <div class="pt-6">
                                            <div class="flex flex-row justify-between items-start gap-2">
                                                <div>
                                                    <span class="font-medium text-surface-500 dark:text-surface-400 text-sm">{{ item.category }}</span>
                                                    <div class="text-lg font-medium mt-1">{{ item.name }}</div>
                                                </div>
                                                <div class="bg-surface-100 p-1" style="border-radius: 30px">
                                                    <div
                                                        class="bg-surface-0 flex items-center gap-2 justify-center py-1 px-2"
                                                        style="
                                                            border-radius: 30px;
                                                            box-shadow:
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.04),
                                                                0px 1px 2px 0px rgba(0, 0, 0, 0.06);
                                                        "
                                                    >
                                                        <span class="text-surface-900 font-medium text-sm">{{ item.rating }}</span>
                                                        <i class="pi pi-star-fill text-yellow-500"></i>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="flex flex-col gap-6 mt-6">
                                                <span class="text-2xl font-semibold">${{ item.price }}</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </DataView>
                </TabPanel>
            </TabPanels>
        </Tabs>
    </div>
</template>

<style lang="scss" scoped></style>
